/**
 * Copyright 2014-2020  the original author or authors.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zatom.newscore.common;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * Entity class of response info.
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class BaseResponse<T> implements Serializable {

    @ApiModelProperty(value = "返回编码")
    private int code;
    @ApiModelProperty(value = "返回信息")
    private String message;
    @ApiModelProperty(value = "返回数据")
    private T data;
    @ApiModelProperty(value = "总数据量")
    private int total;

    public BaseResponse() {
    }

    public BaseResponse(Integer _code, String _message) {
        this.code = _code;
        this.message = _message;
    }

    public BaseResponse(Integer _code, String _message, T data) {
        this.code = _code;
        this.message = _message;
        this.data = data;
    }

    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<T>(200, "", data);
    }

    public static <T> BaseResponse<T> failed(T data) {
        return new BaseResponse<T>(500, "system exception", data);
    }

    public static <T> BaseResponse<T> success() {
        return new BaseResponse<T>(200, "", null);
    }

    public static <T> BaseResponse<T> failed() {
        return new BaseResponse<T>(500, "system exception", null);
    }
}
